sql的嵌套查询,把一次查询的结果做为表继续进一步查询;内联视图 您所在的位置:网站首页 sql 联表查询 最后一条 sql的嵌套查询,把一次查询的结果做为表继续进一步查询;内联视图

sql的嵌套查询,把一次查询的结果做为表继续进一步查询;内联视图

2024-07-05 20:03| 来源: 网络整理| 查看: 265

Mysql的嵌套表查询

  嵌套SELECT语句也叫子查询,一个 SELECT 语句的查询结果能够作为另一个语句的输入值。子查询可以:

出现在Where子句中, 出现在from子句中,作为一个临时表使用, 出现在select list中,作为一个字段值来返回。 示例

1、出现在where子句中

单行子查询 :单行子查询是指子查询的返回结果只有一行数据。当主查询语句的条件语句中引用子查询结果时可用单行比较符号(=, >, =, 、< 、>= 、all (select score from score where stId=(select stId from Student where stName= 'Kaka')));

 

select stName from Student where stId in (select distinct stId from score where score >any(select score from score where stId=(select stId from Student where stName='Kaka'))); 多列子查询:当是单行多列的子查询时,主查询语句的条件语句中引用子查询结果时可用单行比较符号(=, >, =, set autotrace trace exp statSQL> select object_id,object_name,object_type from xxx where object_idcreate table ts as (select object_id,object_name,object_type from xxx where object_id insert into ts values(999,'testbyhao','testtype');

1 row created.1 consistent gets

SQL> insert into (select object_id,object_name,object_type from xxx where object_id



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有